package com.erp.erp_ui.Quoted_Info;

import com.erp.erp_dao.Quoted_Info.QuotedProductPartsInfoDAO;
import com.erp.erp_entitys.Quoted_Info.QuotedInfo;
import com.erp.erp_entitys.Quoted_Info.QuotedProductCostInfo;
import com.erp.erp_entitys.Quoted_Info.QuotedProductInfo;
import com.erp.erp_entitys.Quoted_Info.QuotedProductPartsInfo;
import com.erp.erp_servers.Quoted_Info.QuotedInfoService;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 报价控制器
 *
 * @author LuoXing
 * @version 1.0
 * @date 2020/11/30 19:41
 */
@RestController
@RequestMapping("quotedInfo")
public class QuotedInfoController {

    @Resource
    private QuotedInfoService quotedInfoService;
    /**
     * 保存报价信息
     * @param record
     * @return
     */
    @PostMapping("insert")
    public R<QuotedInfo> insert(@RequestBody QuotedInfo record){
        try{
            return R.build(quotedInfoService.insert(record));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }


    /**
     * 修改报价信息
     * @param record
     * @return
     */
    @PostMapping("update")
    public R<Integer> update(@RequestBody QuotedInfo record){
        try{
            return R.build(quotedInfoService.update(record));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 删除报价信息
     * @param id
     * @return
     */
    @GetMapping("delete")
    public R<Boolean> delete(@RequestParam(value="id",required= true) Long id){
        try{
            return R.build(quotedInfoService.deleteById(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 删除报价产品信息
     * @param id
     * @return
     */
    @GetMapping("deleteProduct")
    public R<Boolean> deleteProduct(@RequestParam(value="id",required= true) Long id){
        try{
            return R.build(quotedInfoService.deleteProduct(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 删除报价信息
     * @param id
     * @return
     */
    @GetMapping("deletePart")
    public R<Boolean> deletePart(@RequestParam(value="id",required= true) Long id){
        try{
            return R.build(quotedInfoService.deletePart(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 删除报价信息
     * @param id
     * @return
     */
    @GetMapping("deleteCost")
    public R<Boolean> deleteCost(@RequestParam(value="id",required= true) Long id){
        try{
            return R.build(quotedInfoService.deleteCost(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping(value = "listByPage")
    public R selectByPage(QuotedInfo record){
        try{
            PageInfo<QuotedInfo> pageInfo = quotedInfoService.selectByPage(record);
            return R.build(200, "success", pageInfo.getTotal(), pageInfo.getList());
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 产品配件分页查询
     * @return
     */
    @GetMapping(value = "listProductByPage")
    public R selectProductsByPage(QuotedProductInfo record){
        try{
            PageInfo<QuotedProductInfo> pageInfo = quotedInfoService.selectProductsByPage(record);
            return R.build(200, "success", pageInfo.getTotal(), pageInfo.getList());
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }


    /**
     * 产品配件分页查询
     * @return
     */
    @GetMapping(value = "listPartByPage")
    public R selectPartsByPage(QuotedProductPartsInfo record){
        try{
            PageInfo<QuotedProductPartsInfo> pageInfo = quotedInfoService.selectPartsByPage(record);
            return R.build(200, "success", pageInfo.getTotal(), pageInfo.getList());
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }

    /**
     * 费用分页查询
     * @return
     */
    @GetMapping(value = "listCostByPage")
    public R selectCostsByPage(QuotedProductCostInfo record){
        try{
            PageInfo<QuotedProductCostInfo> pageInfo = quotedInfoService.selectCostByPage(record);
            return R.build(200, "success", pageInfo.getTotal(), pageInfo.getList());
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }
    }
}
